package com.smzd.ccms.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.smzd.ccms.domain.ChannelConfig;
import com.smzd.ccms.mappers.ChannelConfigMapper;
import com.smzd.core.dao.AbstractDao;
import com.smzd.core.mappers.IMapper;

@Component
public class ChannelConfigDao extends AbstractDao<ChannelConfig> {
	@Autowired
	private ChannelConfigMapper mapper;

	@Override
	protected IMapper<ChannelConfig> getMapper() {
		return mapper;
	}

	public List<ChannelConfig> getAllChannelConfigs() {
		return mapper.getAllChannelConfigs();
	}

	/**
	 * 根据指定的字典表id，获取栏目的所有模板配置，包括被disabled的模板。
	 * @param chId
	 * @param dictids
	 * @return
	 */
	public List<ChannelConfig> getChannelConfigsByDictIds(Integer chId, int[] dictids) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("chId", chId);
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < dictids.length; i++) {
			sb.append(dictids[i]);
			if (i < dictids.length - 1) {
				sb.append(",");
			}
		}
		params.put("dictids", sb.toString());
		return mapper.getChannelConfigsByDictIds(params);
	}

	/**
	 * disable指定的栏目模板配置
	 * @param cfg
	 */
	public void disableChannelConfig(ChannelConfig cfg) {
		mapper.disableChannelConfig(cfg);
	}

	/**
	 * 更新栏目的模板配置，但只更新template的id，并且将该配置enable
	 * @param cfg
	 */
	public void updateChannelConfig(ChannelConfig cfg) {
		mapper.updateChannelConfig(cfg);
	}

	public void removeChannelConfigsForChannel(int chId) {
	    mapper.removeChannelConfigsForChannel(chId);
    }
}